package com.lx.controller;


import com.lx.dao.SysLogDao;
import com.lx.domain.mysyslog;
import com.lx.serv.impl.AdminServImpl;
import com.lx.utill.JwtUtill;
import com.lx.utill.TimeUtill;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping(value = "/SysLog")
public class SysLogController {
    @Autowired
    private SysLogDao sysLogDao;
    @Autowired
    private AdminServImpl adminServImpl;

    // 获取系统日志列表
    @GetMapping
    public Result getSysLogList(@RequestHeader String token) {
        if (!JwtUtill.VerifyToken(token)) {
            sysLogDao.insert(new mysyslog(TimeUtill.getTime(), "失效用户", "获取日志列表", "获取失败"));
            return new Result(Code.GET_FAIL, "获取失败", null);
        }
        String username = adminServImpl.getNameBytoken(token);
        List<mysyslog> logs = sysLogDao.selectList(null);
        sysLogDao.insert(new mysyslog(TimeUtill.getTime(), username, "获取日志列表", "获取成功"));
        return new Result(Code.GET_SUCCESS, "获取成功", logs);
    }

}
